package com.example.mapp;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

import com.example.entity.authority.UserMetastasis;
import com.example.ext.entity.ExtUserMetastasis;

/**
 * Created by simon on 2018/12/19.
 */
@Mapper
public interface UserMetastasisMapp {

    @Insert(" insert into user_metastasis (user_id,user_name,from_id, from_name,to_id,to_name,apply_time,approval_time,state) " +
            "value (#{userId},#{userName},#{fromId},#{fromName},#{toId},#{toName},#{applyTime},#{approvalTime},#{state})")
    @SelectKey(statement = "select last_insert_id()", keyProperty = "id", keyColumn = "id", before = false, resultType = Long.class)
    int insert(UserMetastasis userMetastasis) throws Exception;

    @Update(" update user_metastasis set state=#{state}, remark=#{remark} where id=#{id}")
    int update(UserMetastasis userMetastasis) throws Exception;

    @Select(" select a.*,b.user_code,b.role_type_id,b.card_type,b.card_number,b.card_type_number,b.mobile,b.email,"
    		+ "b.phone,b.role_id,b.file_list,b.face_url,b.firstgt from user_metastasis a inner join sys_user b on a.user_id = b.id where to_id = #{toId} order by state")
    List<ExtUserMetastasis> findTomy(String toId) throws Exception;

    @Select(" select * from user_metastasis where user_id = #{userId} and state='1' ")
    List<UserMetastasis> findMyTransfer(String userId) throws Exception;
}
